package cn.micai.base.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/21 15:21
 */
public class BeforeJava8 {

    public static void main(String [] args) {

        /*List<String> lines = Arrays.asList("spring", "node", "mkyong");

        List<String> result = getFilterOutput(lines, "mkyong");

        for (String temp :result) {
            System.out.println(temp); //output : spring, node
        }*/

        List<Person> persons = Arrays.asList(new Person("mkyong", 30),
                    new Person("jack", 20),
                    new Person("lawrence", 40));

        Person result = getPersonByName(persons, "jack");
        System.out.println(result);


    }

    private static Person getPersonByName(List<Person> persons, String name) {
        Person person = null;

        for (Person temp : persons) {
            if (name.equals(temp.getName())) {
                person = temp;
            }
        }

        return person;

    }

    private static List<String> getFilterOutput(List<String> lines, String filter) {
        List<String> result = new ArrayList<>();

        for (String line : lines) {
            // we dont like mkyong
            if (!"mkyong".equals(line)) {
                result.add(line);
            }
        }
        return result;
    }
}
